package com.lc.user.express.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lc.user.express.R;
import com.lc.user.express.app.AppContext;
import com.lc.user.express.model.AddrModel;

import java.util.List;

/**
 * Created by Administrator on 2016/3/18.
 */
public class SearchAddrAdapter extends BaseListAdapter<AddrModel> {
    public SearchAddrAdapter(Context context, List<AddrModel> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        AddrModel model = data.get(position);
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_search_addr, null);
            AppContext.ScaleScreenHelper.loadView((ViewGroup) convertView);
            viewHolder = new ViewHolder();
            viewHolder.tv_addr = (TextView) convertView.findViewById(R.id.tv_addr);
            viewHolder.tv_district = (TextView) convertView.findViewById(R.id.tv_district);
            convertView.setTag(viewHolder);

        }
        setContentView(convertView, model);
        return convertView;
    }

    private void setContentView(View contentView, AddrModel model) {
        ViewHolder viewHolder = (ViewHolder) contentView.getTag();
        viewHolder.tv_addr.setText(model.getAddr());
        viewHolder.tv_district.setText(model.getDistrict());
    }

    private class ViewHolder {
        TextView tv_addr;
        TextView tv_district;
    }
}
